//
//  goodsView.swift
//  NewDelivery
//
//  Created by 天下宅 on 2016/11/10.
//  Copyright © 2016年 天下宅. All rights reserved.
//

import UIKit
import SwiftyJSON
class GoodsModel: NSObject {
    var name:String
    var count:String
    var price:String
    var id:String
    var order_id:String
    
    init(WithDict dict:[String:JSON]) {
        name = dict["goodsname"]!.stringValue
        count = dict["goodscount"]!.stringValue
        price = dict["goodscost"]!.stringValue
        id = dict["id"]!.stringValue
        order_id = dict["order_id"]!.stringValue

    }
    
//    override init() {
//        name = "柯基"
//        count = "2份"
//        price = "￥30.00元"
//    }
    
}

class GoodsView: UIView {

    private var nameLabel:UILabel!
    private var countLabel:UILabel!
    private var priceLabel:UILabel!

    var thisModel:GoodsModel!
    

    static func creatGoodsView(WithModel model:GoodsModel) -> GoodsView
    {
        let v = GoodsView()
        v.thisModel = model
        v.setInterFace()
        return v
    }
    

    
    func setInterFace()
    {
        self.size = CGSize.init(width: screenWidth, height: 50)
        nameLabel = UILabel.init(frame: CGRect.init(x: 10, y: 0, width: screenWidth / 2.0 * 0.8, height: 50))
        self.addSubview(nameLabel)
        
        countLabel = UILabel.init(frame: .init(x: nameLabel.right + 5, y: 0, width: 60, height: 50))
        self.addSubview(countLabel)
        countLabel.text = thisModel.count
        
        priceLabel = UILabel.init(frame: .init(x: screenWidth - 120, y: 0, width: 110, height: 50))
        self.addSubview(priceLabel)
        priceLabel.text = "￥" + thisModel.price
        priceLabel.textAlignment = NSTextAlignment.right
        nameLabel.text = thisModel.name
        
        self.addLine(WithColor: .lightGray, model: [.bottom])
    }
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
